#ifndef DATAPOSTBACK_H
#define DATAPOSTBACK_H

#pragma once

#include <QObject>
#include <QTcpSocket>

namespace ns_yht
{
#define DATAPOSTBACK DataPostback::instance()
    class DataPostback : public QObject
    {
        Q_OBJECT
    public:
        DataPostback();
        ~DataPostback();

        static DataPostback *instance();

        void moveToThreadEx(QThread *thread);
        void setPostBack(bool postBack);
        // bool getPostBack() const;

    public slots:
        void onNetworkStatusChanged(bool state);
        void sendBack(const QByteArray &msg);

    private slots:
        void onConnected();
        void onDisconnected();
        void onError(QAbstractSocket::SocketError socketError);

    private:
        void openSocket();
        void closeSocket();
        QString getServer() const;

        QTcpSocket *m_tcpSocket{nullptr};
        bool m_postBack{false};
    };

}

#endif